using System;
using System.Collections.Generic;
using System.Text;

namespace Dare.Utilities.Net.FTPClient
{
    public class FtpResponseMessage
    {
        public FtpResponseMessage()
            : this(0, String.Empty)
        {

        }

        public FtpResponseMessage(int responseCode, string responseMessage)
        {
            this.responseCode = responseCode;
            this.responseMessage = responseMessage;
        }

        private int responseCode;
        public int ResponseCode
        {
            get { return responseCode; }
        }

        private string responseMessage;
        public string ResponseMessage
        {
            get { return responseMessage; }
        }

        public override string ToString()
        {
            return String.Format("{0:000} {1}", responseCode, responseMessage);
        }

        public static FtpResponseMessage Parse(string message)
        {
            if (message.Length > 3)
            {
                int code = 0;
                if (int.TryParse(message.Substring(0, 3), out code))
                {
                    return new FtpResponseMessage(code, message.Substring(3).Trim());
                }
            }
            return new FtpResponseMessage(0, message);
        }
    }
}
